import { request } from 'umi';

export async function fakeAttachment(): Promise<{ data: AircasKB.Knowledge.AttachmentItem[] }> {
    return request('/mockApi/fake_knowledge_attachment');
}

export async function fakeRelevance(): Promise<{ data: AircasKB.Knowledge.RelevanceItem[] }> {
    return request('/mockApi/fake_knowledge_relevance');
}

export async function fakeKnowledge(): Promise<{ data: AircasKB.Knowledge.KnowledgeItem[] }> {
    return request('/mockApi/fake_knowledge');
}

export async function fakeQuote(): Promise<{ data: AircasKB.Knowledge.QuoteItem[] }> {
    return request('/mockApi/fake_knowledge_quote');
}

//查询知识类型列表
export async function getKnowledgeTypesData(options?: {
    [key: string]: any;
}): Promise<AircasKB.Knowledge.KnowledgeTypesResponse[]> {
    const result: AircasKB.ResponseType<AircasKB.Knowledge.KnowledgeTypesResponse[]> = await request<
        AircasKB.ResponseType<AircasKB.Knowledge.KnowledgeTypesResponse[]>
    >('/aircaskb/knowledgeDict/getKnowledgeTypes', {
        method: 'GET',
        ...(options || {}),
    });
    if (result.success) {
        return result?.data ?? [];
    }
    return [];
}

//列表查询知识分类
export async function getClassificationListData(body:AircasKB.Knowledge.ClassificationRequestParams,options?: {
    [key: string]: any;
}){
    const { parentId,parentIds } = body;
    return  request<AircasKB.ResponseType<AircasKB.Knowledge.classificationListResponse[]>>(
        `/aircaskb/classification/list?parentId=${parentId||""}&parentIds=${parentIds||""}`,
        {
        method: 'POST',
        ...(options || {}),
    });
}

//列表查询知识分类-通过code
export async function getClassificationListDataToCode(body:AircasKB.Knowledge.ClassificationCodeRequestParams,options?: {
    [key: string]: any;
}){
    const { code,type } = body;
    return  request<AircasKB.ResponseType<AircasKB.Knowledge.classificationListResponse[]>>(
        `/aircaskb/classification/findListByCode?code=${code||""}&type=${type||""}`,
        {
            method: 'GET',
            ...(options || {}),
        });
}

//获取附件类型
export async function getAttachmentTypeData(options?: {[key: string]: any}){
   return  request<AircasKB.ResponseType<AircasKB.Knowledge.AttachmentTypeResponse[]>>(
        `/aircaskb/knowledgeDict/getAttachmentType`, {
        method: 'GET',
        ...(options || {}),
    });
}

//获取章节类型
export async function getChapterTypesData(options?: {[key: string]: any}){
    return  request<AircasKB.ResponseType<AircasKB.Knowledge.ChapterTypesResponse[]>>(
        `/aircaskb/knowledgeDict/getChapterTypes`, {
            method: 'GET',
            ...(options || {}),
        });
}

//获取关联类型
export async function getAssociativeTypeData(options?: {[key: string]: any}){
    return  request<AircasKB.ResponseType<AircasKB.Knowledge.AssociativeTypeResponse[]>>(
        `/aircaskb/knowledgeDict/getAssociativeType`, {
            method: 'GET',
            ...(options || {}),
        });
}

//获取参考引用类型
export async function getReferenceTypesData(options?: {[key: string]: any}){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.ReferenceTypesResponse[]>>(
        `/aircaskb/knowledgeDict/getReferenceTypes`, {
            method: 'GET',
            ...(options || {}),
        });
}


//知识基本信息添加
export async function BaseInfoSaveRequest(body:AircasKB.Knowledge.BaseInfoSaveRequestParams, options?: {[key: string]: any}){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.BaseInfoSaveResponse>>(
        `/aircaskb/knowledge/baseInfo/save`, {
            method: 'POST',
            data:body,
            ...(options || {}),
        });
}

//章节添加
export async function ChapterSaveRequest(body:AircasKB.Knowledge.ChapteSaveRequestParams, options?: {[key: string]: any}){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.ChapteSaveResponse>>(
        `/aircaskb/knowledge/chapter/save`, {
            method: 'POST',
            data:body,
            ...(options || {}),
        });
}

//知识产权添加
export async function  PermissionSaveRequest(body:AircasKB.Knowledge.PermissionSaveRequestParams, options?: {[key: string]: any}){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.PermissionSaveResponse>>(
        `/aircaskb/knowledge/permission/save`, {
            method: 'POST',
            data:body,
            ...(options || {}),
        });
}

//库内知识关联
export async function  AssociativeRequest(body:AircasKB.Knowledge.AssociativeRequestParams, options?: {[key: string]: any}){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.AssociativeResponse>>(
        `/aircaskb/knowledge/associative/save`, {
            method: 'POST',
            data:body,
            ...(options || {}),
        });
}

//库内知识关联解除
export async function  AssociativeDelRequest(body:AircasKB.Knowledge.AssociativeDelRequestParams, options?: {[key: string]: any}){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.AssociativeDelResponse>>(
        `/aircaskb/knowledge/associative/del`, {
            method: 'POST',
            data:body,
            ...(options || {}),
        });
}


//获取参考引用接口
export async function ReferenceListRequest(
    body:AircasKB.Knowledge.ReferenceListRequestParams,
    options?: {[key: string]: any;
    }){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.ReferenceListResponse[]>>(
        `/aircaskb/knowledge/reference/list`,
        {
            method:"POST",
            data:body,
            ...(options || {}),});
}


//知识参考引用删除
export async function  ReferenceDelRequest(body:AircasKB.Knowledge.ReferenceDelRequestParams, options?: {[key: string]: any}){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.ReferenceDelResponse>>(
        `/aircaskb/knowledge/reference/del`, {
            method: 'POST',
            data:body,
            ...(options || {}),
        });
}


//知识参考引用添加
export async function  ReferenceSaveRequest(body:AircasKB.Knowledge.ReferenceSaveRequestParams, options?: {[key: string]: any}){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.ReferenceSaveResponse>>(
        `/aircaskb/knowledge/reference/save`, {
            method: 'POST',
            data:body,
            ...(options || {}),
        });
}

//知识查询
export async function  KnowledgeSearchRequest(body:AircasKB.Knowledge.KnowledgeSearchRequestParams, options?: {[key: string]: any}){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.KnowledgeSearchResponse>>(
        `/aircaskb/knowledge/simple/search`, {
            method: 'POST',
            data:body,
            ...(options || {}),
        });
}

//列表查询知识自定义属性
export async function  KnowledgeCusFieldRequest(
    body:AircasKB.Knowledge.KnowledgeCusFieldRequestParams,
    options?: {[key: string]: any}
){
    const { knowledgeType } = body
    return request<AircasKB.ResponseType<AircasKB.Knowledge.KnowledgeCusFieldResponse[]>>(
        `/aircaskb/knowledgeCusField/list?knowledgeType=${knowledgeType}`, {
            method: 'GET',
            ...(options || {}),
        });
}

//附件列表
export async function  AttachmentListRequest(body:AircasKB.Knowledge.AttachmentListRequestParams, options?: {[key: string]: any}){
    const { knowledgeId } = body
    return request<AircasKB.ResponseType<AircasKB.Knowledge.AttachmentListResponse[]>>(
        `/aircaskb/attachment/list?knowledgeId=${knowledgeId}`, {
            method: 'GET',
            ...(options || {}),
        });
}

//删除附件
export async function  DelAttachmentRequest(body:AircasKB.Knowledge.DelAttachmentRequestParams, options?: {[key: string]: any}){
    const { id } = body
    return request<AircasKB.ResponseType<AircasKB.Knowledge.DelAttachmentResponse>>(
        `/aircaskb/attachment/delete?id=${id}`, {
            method: 'GET',
            ...(options || {}),
        });
}
// export async function AttachmentListRequest(body:AircasKB.Knowledge.AttachmentListRequestParams, options?: {
//     [key: string]: any;
// }): Promise<{ data: AircasKB.Knowledge.AttachmentListResponse[] }>{
//     const { knowledgeId } = body
//    return request(`/aircaskb/attachment/list?knowledgeId=${knowledgeId}`,{method:"GET", ...(options || {}),});
// }

//附件上传
export async function  uploadKnowledgeAttachmentRequest(
    body:AircasKB.Knowledge.uploadKnowledgeAttachmentRequestParams,
    options?: {[key: string]: any}){
    const { file,knowledgeId,title,type,cusLabel} = body;
    const fd = new FormData();
    fd.append('file', file)
    knowledgeId && fd.append('knowledgeId',knowledgeId)
    title && fd.append('title',title)
    type && fd.append('type',type)
    cusLabel && fd.append('cusLabel',cusLabel)

    // return fetch(`/aircaskb/attachment/uploadKnowledgeAttachment`, { //fetch请求
    //     method: 'POST',
    //     body: fd,
    // });
    return request<AircasKB.ResponseType<AircasKB.Knowledge.uploadKnowledgeAttachmentResponse>>(
        `/aircaskb/attachment/uploadKnowledgeAttachment`, {
            method: 'POST',
            data:fd,
            requestType: 'form',
            ...(options || {}),
        });
}

//获取章节模板
export async function knowledgeChapterTemplateRequest(
    body:AircasKB.Knowledge.KnowledgeChapterTemplateRequestParams,
    options?: {[key: string]: any;}){
    const { knowledgeType } = body
    return request <AircasKB.ResponseType<AircasKB.Knowledge.KnowledgeChapterTemplateResponse[]>>
    (`/aircaskb/knowledgeChapter/getTemplate?knowledgeType=${knowledgeType}`,
        {
            method:"GET",
            ...(options || {}),
        });
}

//保存知识模板到知识
// export async function SaveTemplateToKnowledgeRequest(body:AircasKB.Knowledge.SaveTemplateToKnowledgeRequestParams, options?: {
//     [key: string]: any;
// }): Promise<{ data: AircasKB.Knowledge.SaveTemplateToKnowledgeResponse[] }>{
//     const { knowledgeId } = body
//     return request(`/aircaskb/knowledgeChapter/saveTemplateToKnowledge?knowledgeId=${knowledgeId}`,{method:"GET", ...(options || {}),});
// }
//保存知识模板到知识
export async function SaveTemplateToKnowledgeRequest(
    body:AircasKB.Knowledge.SaveTemplateToKnowledgeRequestParams,
    options?: {[key: string]: any;}){
    const { knowledgeId } = body
    return request <AircasKB.ResponseType<AircasKB.Knowledge.SaveTemplateToKnowledgeResponse[]>>
    (`/aircaskb/knowledgeChapter/saveTemplateToKnowledge?knowledgeId=${knowledgeId}`,
        {
            method:"GET",
            ...(options || {}),
        });
}

//获取用户列表
export async function KnowledgeUserListRequest(
    body:AircasKB.Knowledge.KnowledgeUserListRequestParams,
    options?: {[key: string]: any;}){
    const { userName } = body;
    return request <AircasKB.ResponseType<AircasKB.Knowledge.KnowledgeUserListResponse[]>>
    (`/aircaskb/knowledgeUser/userList?userName=${userName}`,
        {
            method:"GET",
            ...(options || {}),
        });
}

//查询知识产权所有人
export async function KnowledgeUserOwenRequest(
    body:AircasKB.Knowledge.KnowledgeUserOwenRequestParams,
    options?: {[key: string]: any;}){
    const { knowledgeId } = body
    return request <AircasKB.ResponseType<AircasKB.Knowledge.KnowledgeUserOwenResponse[]>>
    (`/aircaskb/knowledgeUser/getOwenList?knowledgeId=${knowledgeId}`,
        {
            method:"GET",
            ...(options || {}),
        });
}

//查询关联的知识，包括我关联的和关联我的
export async function KnowledgeAssociativeRequest(
    body:AircasKB.Knowledge.KnowledgeAssociativeRequestParams,
    options?: {[key: string]: any;
}){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.KnowledgeAssociativeResponse>>(
        `/aircaskb/knowledge/associative/search`,
        {
            method:"POST",
            data:body,
            ...(options || {}),});
}

//下载附件
export async function GetAttachmentPathRequest(
    body:AircasKB.Knowledge.GetAttachmentPathRequestParmas,
    options?: {[key: string]: any;
    }){
    const { attachmentId } = body;
    return request<AircasKB.ResponseType<string>>(
        `/aircaskb/attachment/getAttachmentPath?attachmentId=${attachmentId}`,
        {
            method:"GET",
            ...(options || {}),});
}

//根据知识id查询章节列表
export async function knowledgeChapterToKidRequest(
    body:AircasKB.Knowledge.KnowledgeChapterToKidRequestParams,
    options?: {[key: string]: any;
    }){

    const { knowledgeId } = body;
    return request<AircasKB.ResponseType<AircasKB.Knowledge.KnowledgeChapterToKidResponse[]>>(
        `/aircaskb/knowledgeChapter/findByKnowledgeId?knowledgeId=${knowledgeId}`,
        {
            method:"GET",
            ...(options || {}),});
}

//根据id查询章节详情
export async function knowledgeChapterToIdRequest(
    body:AircasKB.Knowledge.KnowledgeChapterToIdRequestParams,
    options?: {[key: string]: any;
    }){

    const { id } = body;
    return request<AircasKB.ResponseType<AircasKB.Knowledge.KnowledgeChapterToIdResponse>>(
        `/aircaskb/knowledgeChapter/get?id=${id}`,
        {
            method:"GET",
            ...(options || {}),});
}

//知识章节书删除
export async function DelChapterRequest(
    body:AircasKB.Knowledge.DelChapterRequestParams,
    options?: {[key: string]: any;
    }){
    return request<AircasKB.ResponseType<AircasKB.Knowledge.DelChapterResponse>>(
        `/aircaskb/knowledge/chapter/del`,
        {
            method:"POST",
            data:body,
            ...(options || {}),});
}

//上传静态资源
export async function StaticResourceUploadRequest(
    body:AircasKB.Knowledge.StaticResourceUploadRequestParams,
    options?: {[key: string]: any;
    }){
    const { file} = body;
    const fd = new FormData();
    fd.append('file', file)
    return request<AircasKB.ResponseType<string>>(
        `/aircaskb/aircaskbObject/staticResourceUpload`,
        {
            method:"POST",
            data:fd,
            requestType: 'form',
            ...(options || {}),});
}


//查询知识详情
export async function GetKnowledgeBaseInfoRequest(
    body:AircasKB.Knowledge.GetKnowledgeBaseInfoRequestParams,
    options?: {[key: string]: any;
    }){
    const { id } = body;
    return request<AircasKB.ResponseType<AircasKB.Knowledge.GetKnowledgeBaseInfoResponse>>(
        `/aircaskb/knowledge/baseInfo/get?id=${id}`,
        {
            method:"GET",
            ...(options || {}),});
}


//查询知识详情页面信息
export async function GetKnowledgeDetailsRequest(
    body:AircasKB.Knowledge.GetKnowledgeDetailsRequestParams,
    options?: {[key: string]: any;
    }){
    const { knowledgeId } = body;
    return request<AircasKB.ResponseType<AircasKB.Knowledge.GetKnowledgeDetailsResponse>>(
        `/aircaskb/knowledge/baseInfo/getDetails?knowledgeId=${knowledgeId}`,
        {
            method:"GET",
            ...(options || {}),});
}







